/*
 * Created on 29/06/2005
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package br.ufmg.dees.insane.ui.rich.learn.learn_view.strain_view;

import java.awt.BorderLayout;
import java.awt.event.KeyEvent;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JToolBar;
import javax.swing.text.Position;

import br.ufmg.dees.insane.model.disc.fem.FemModel;
import br.ufmg.dees.insane.ui.rich.learn.learn_controller.StrainController;
import br.ufmg.dees.insane.ui.rich.learn.learn_view.CmdButton;
import br.ufmg.dees.insane.ui.rich.learn.learn_view.CmdMenu;
import br.ufmg.dees.insane.ui.rich.learn.learn_view.DrawingArea;
import br.ufmg.dees.insane.ui.rich.learn.learn_view.IView;
import br.ufmg.dees.insane.ui.rich.learn.learn_view.LearnInterface;
import br.ufmg.dees.insane.ui.rich.learn.learn_view.LearnView;
import br.ufmg.dees.insane.ui.rich.learn.learn_view.LearnViewState;
import br.ufmg.dees.insane.ui.rich.learn.learn_view.command.Command;
import br.ufmg.dees.insane.ui.rich.learn.learn_view.command.SelectCommand;
import br.ufmg.dees.insane.ui.rich.learn.learn_view.strain_view.command.BMatrixCommand;
import br.ufmg.dees.insane.ui.rich.learn.learn_view.strain_view.command.GetStrainCommand;
import br.ufmg.dees.insane.ui.rich.learn.learn_view.strain_view.command.Help2Command;

/**
 * @author Francisca
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class StrainView extends LearnView {  
	
	//  No da arvore: Strain
	private Command bMatrixCmd = new BMatrixCommand(parent);
	private Command getStrainCmd = new GetStrainCommand(parent);
	private Command help2Cmd = new Help2Command(parent);
	
	//	No Strain
    private CmdMenu itemBMatrix = new CmdMenu("B Matrix", new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/Deform.gif")));
    private CmdMenu itemGetStrain = new CmdMenu("Get Strain", new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/Stress.gif")));
    private CmdMenu itemHelp2 = new CmdMenu("Help", new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/Help16.gif")));

    
    //No Strain
    private CmdButton bMatrix = new CmdButton(new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/Deform.gif")));
    private CmdButton getStrain = new CmdButton(new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/Stress.gif")));
    private CmdButton help2 = new CmdButton(new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/Help16.gif")));
   
    private JMenu menuStrainXDisplacements = new JMenu("StrainXDisplacements");
    protected JToolBar strainXDisplacementsToolBar = new JToolBar();
    
	public StrainView(LearnInterface parent, FemModel m){
	    super(parent,m);
		super.setViewState(new LearnViewState());
		super.setDrawingArea(new DrawingArea((IView)this));
		super.setController(new StrainController(this));
		
		//Setting menu Strain
		menuStrainXDisplacements.add(itemBMatrix);
		itemBMatrix.setCommand(bMatrixCmd);
		itemBMatrix.setEnabled(false);
		itemBMatrix.setMnemonic(KeyEvent.VK_B);
		itemBMatrix.addActionListener(parent);
        
		menuStrainXDisplacements.add(itemGetStrain);
		itemGetStrain.setCommand(getStrainCmd);
		itemGetStrain.setEnabled(false);
		itemGetStrain.setMnemonic(KeyEvent.VK_S);
		itemGetStrain.addActionListener(parent);
		     
		menuStrainXDisplacements.add(itemHelp2);
        itemHelp2.setCommand(help2Cmd);
        itemHelp2.setEnabled(false);
        itemHelp2.setMnemonic(KeyEvent.VK_H);
        itemHelp2.addActionListener(parent);
        
        strainXDisplacementsToolBar.add(bMatrix);
        bMatrix.setToolTipText("B Matrix");
        bMatrix.addActionListener(parent);
        bMatrix.setCommand(bMatrixCmd);
        
        strainXDisplacementsToolBar.add(getStrain);
        getStrain.setToolTipText("Get Strain");
        getStrain.addActionListener(parent);
        getStrain.setCommand(getStrainCmd);
               
        strainXDisplacementsToolBar.add(help2);
		help2.setToolTipText("Help");
		help2.addActionListener(parent);
		help2.setCommand(help2Cmd);
        
	}
	
	public void init(){
	    super.init();
			parent.getMenuPanel().removeAll();
			parent.getMenuPanel().add(menuFile);
			itemSave.setEnabled(true);
			itemSaveAs.setEnabled(true);
			itemClose.setEnabled(true);
			itemPrint.setEnabled(true);
			menuExport.setEnabled(true);
			menuImport.setEnabled(true);
			parent.getMenuPanel().add(menuEdit);
			parent.getMenuPanel().add(menuView);
			parent.getMenuPanel().add(menuStrainXDisplacements);
			menuStrainXDisplacements.setEnabled(true);
			itemBMatrix.setEnabled(true);
			itemGetStrain.setEnabled(true);
			itemHelp2.setEnabled(true);
			parent.getMenuPanel().add(menuSettings);
			parent.getMenuPanel().add(menuHelp);
	        
			parent.getToolPanel().removeAll();
			parent.getToolPanel().add(fileToolBar);
			save.setEnabled(true);
			saveAs.setEnabled(true);
			print.setEnabled(true);
			delete.setEnabled(false);
			parent.getToolPanel().add(editToolBar);
			parent.getToolPanel().add(zoomToolBar);
			parent.getToolPanel().add(strainXDisplacementsToolBar);
			bMatrix.setEnabled(true);
			getStrain.setEnabled(true);
			help2.setEnabled(true);
							
	        parent.getConsolePanel().setVisible(true);
			
			grid.setEnabled(true);
			snap.setEnabled(true);
			
			this.getDrawingArea().setRepainting(false);
			this.getDrawingArea().repaint();
	        
			parent.getConsoleHandler().setToCommandMode();
			parent.getConsoleHandler().setKeybCommand(null);
			
			this.setStateButtons();
			
			parent.getTree().setEnabled(true);
			parent.getTree().setSelectionPath(parent.getTree().getNextMatch("StrainXDisplacements", 0, Position.Bias.Forward));
			
			this.getController().compose();

			parent.getDrawPanel().removeAll();
			parent.getDrawPanel().add(this.getDrawingArea(), BorderLayout.CENTER);
			this.getDrawingArea().removeAllCommands();
			this.getDrawingArea().setClickedCommand(new SelectCommand(parent));
			this.getDrawingArea().setCursor();
			parent.getDrawPanel().repaint();
			parent.getDrawPanel().updateUI();
			
			parent.getJMenuBar().updateUI();
			parent.repaint();
	    }   

	public  JFrame getInterface(){
    	return parent;
    }
    
	public void setInterface(JFrame par){
    	this.parent = (LearnInterface)par;
    }

    public void setCoord(String x, String y){
    	this.parent.setCoord(x, y);
    }
    
    public void setMessage(String m){
    	this.parent.setMessage(m);
    }

}
